home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / sharew / elektro / lsim_21 / burble.txt < prev    next >
Encoding:
Text File  |  1989-04-23  |  49.5 KB  |  1,359 lines

  1.  
  2.  
  3.  
  4.      ----------------------------------------------------------------
  5.      |  WELCOME to the instruction manual for Lsim on the Atari ST  |
  6.      ----------------------------------------------------------------
  7.  
  8.  
  9.  
  10.      Congratulations on deciding to read the manual. May you live long and 
  11. prosper. This manual goes with Lsim version 2.1.
  12.  
  13.  
  14.  
  15.  
  16.      Table  of  contents ...
  17.      =====  ==  ======== ===
  18.  
  19.  
  20.           Section  1     Introduction
  21.  
  22.           Section  2     What LSIM.TOS does
  23.  
  24.           Section  3     The Lsim circuit description language
  25.  
  26.                          3.1  Circuit description statements
  27.                          3.2  Declaration statements
  28.                          3.3  Character set and comments
  29.  
  30.           Section  4     The nature of the interactive simulation
  31.  
  32.                          4.1  Input
  33.                          4.2  Progress through time
  34.                          4.3  Cheating
  35.  
  36.           Section  5     Running Lsim
  37.  
  38.           Appendix 1     Quick key guide
  39.           Appendix 2     Summary of the Lsim language
  40.           Appendix 3     Operator truth tables
  41.           Appendix 4     Flip-flops in the Lsim language
  42.  
  43.  
  44.           Please don't start by reading the appendixes ...
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.      Section 1                 Introduction
  55.  
  56.  
  57.  
  58.      The standard method of designing a piece of digital electronics can 
  59. be broken down into these four steps:-
  60.  
  61.   1) A specification is made.
  62.      This step outputs a document saying what the hardware must do.
  63.  
  64.   2) An electronic circuit which implements the specification is designed.
  65.      This step outputs a circuit diagram.
  66.  
  67.   3) A prototype of the circuit is built.
  68.      This step outputs a physical circuit, built either with a bread board 
  69.      technique such as wire-wrap, or directly onto a prototype of the PCB 
  70.      for the product.
  71.  
  72.   4) The prototype is tested and debugged.
  73.      Usually this involves generating test inputs for the electronics, and 
  74.      monitoring its outputs to see what it does. Faults in the prototype 
  75.      are corrected until it performs as specified.
  76.  
  77.  
  78.      LSIM.TOS provides a logically (but not electronicly) accurate soft-
  79. ware simulation of any digital circuit made from the basic gates: AND; OR; 
  80. XOR; NOT; and tristate buffers. More complex circuit elements, such as 
  81. flip-flops, can easily be simulated using standard arrangements of gates.
  82.  
  83.      Although this version of Lsim does only the absolute minimum that a 
  84. simulator might be expected to do, it is still a big leap forward from no 
  85. simulator at all.
  86.  
  87.      Usually the last thing done in step 2 (above) is to check the circuit 
  88. diagram to make sure that the digital electronics functions as intended by 
  89. the specification. Usually this checking is done "by hand" (i.e. by human 
  90. brain). At the very least Lsim offers a computer aid for this checking. 
  91. There are several advantages to using the computer aid.
  92.  
  93.      Checking what a logic circuit does by hand is tedious and boring, so 
  94. it tends to be put off or avoided whenever possible. Lsim makes this 
  95. checking quick and easy, so it doesn't get put off.
  96.  
  97.      The unaided human brain is notoriously error prone when performing 
  98. relatively mechanical tasks, such as checking logic. Computers, of course, 
  99. are notoriously good at such tasks.
  100.  
  101.      Effort spent checking the circuit before physical prototyping in step 
  102. 3 (above) pays off amply at step 4 (above). Even with expensive tools like 
  103. logic analysers and storage scopes, finding a logical fault in a digital 
  104. circuit is not necessarily easy. Modifying a physical prototype is much 
  105. more time consuming and difficult than modifying a software simulation. 
  106. Also you can copy a software simulation and hack around with the copy as 
  107. much as you like, knowing that the original is just a disk access away. 
  108. Frequently there is only 1 physical prototype, which must be treated with 
  109. care.
  110.  
  111.      If a significant amount of the logic is in PALs or other PLDs a 
  112. further difficulty can occur. In the process of locating a logical fault 
  113. in the circuit being checked you may find yourself wanting to probe a 
  114. point inside a chip. This is perfectly straight forward on a software 
  115. simulation, but absolutely impossible on a physical circuit. This kind of 
  116. problem will get worse as the complexity of PALs etc. increases.
  117.  
  118.      Indeed most PAL design software (Abel & Palasm) provides rudimentary 
  119. simulation. However I find this kind of apply test vectors to the PAL 
  120. equations and check their outputs simulation clumsy to use. It is not 
  121. interactive. Also the maximum size of the simulation is often only 1 PAL, 
  122. which must be of a type that the software already knows about.
  123.  
  124.      My interest in logic simulation began at the same time as my interest 
  125. in designing with PALs. I used to design random logic with 7400 style 
  126. chips using a circuit diagram as the working metaphor. Now I design random 
  127. logic as a set of PAL definition equations, using boolean algebra as the 
  128. working metaphor. Using the the simulator I check each part as I go along, 
  129. building up a simulation of all the random logic by the end of the design.
  130.  
  131.      On the basis of this "taster" experience I would say that the use of 
  132. programmable logic coupled with really high quality simulation and CAD 
  133. layout has the capacity to change the practice of hardware design as much 
  134. as the replacement of punched card reader and line printer by keyboard and 
  135. VDU has changed the practice of software design.
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.      Section 2             What  LSIM.TOS  does
  146.                             
  147.  
  148.  
  149.      The digital circuit to be simulated is defined in a text description 
  150. language based on boolean algebra. The text description is stored as a 
  151. straight ASCII file, easily edited by the word processor of your choice. 
  152. Unlike Palasm the Lsim language is fairly free format.
  153.  
  154.      When Lsim is run it reads the text description file and compiles it 
  155. to a data base for use by the simulation part of the program. Any errors 
  156. in the file format are displayed on the screen. There is also an option to 
  157. create an output file containing a listing of the input with the error 
  158. messages added to it. If there are no input errors Lsim automatically 
  159. proceeds to simulate the circuit.
  160.  
  161.      During simulation you have control over the logic levels of a number 
  162. of points in the circuit. At any time you can ask the program to calculate 
  163. the next logical state of the circuit. There are 2 reasons why Lsim 
  164. doesn't mimic a real circuit, and automatically go to the next state every 
  165. time you change a logic level. Firstly it would make it impossible to 
  166. change 2 (or more) levels at once, and secondly it would leave no 
  167. opportunity to correct typing errors.
  168.  
  169.      Lsim doesn't model gate propagation delays. It assumes only that the 
  170. output of a gate changes state after the inputs change state. When it 
  171. calculates the next logical state of the circuit Lsim waits until all the 
  172. gates have done all their state changes before outputting the next circuit 
  173. state.
  174.  
  175.      Lsim keeps track of the past states of all the circuit signals named 
  176. in the text description. This information is presented as a character 
  177. based timing diagram which is scrollable horizontally and, if there are 
  178. more than 25 named signals, vertically.
  179.  
  180.      Lsim recognises and displays 5 states that a signal may be in. As 
  181. well as the regular states of logic high, logic low and tristated (high 
  182. impedance) Lsim uses contended and undetermined. A contended state appears 
  183. when the outputs of 2 (or more) gates with different non-tristate logic 
  184. levels are shorted together.
  185.  
  186.      An undetermined state appears when Lsim can't work out what the state 
  187. of a signal should be. For example the output of a NOT gate with a 
  188. tristated input is undetermined. Watch out for this undetermined state as 
  189. its cause can be quite subtle. For example if you create a flip-flop that 
  190. has no reset line then there is no way to tell what state it should be in 
  191. at power up. Lsim will show its output as undetermined until data is 
  192. clocked into the flip-flop.
  193.  
  194.       The use of undetermined as a state might be called logic simulation 
  195. for paranoids. It prevents a circuit working in the simulator as a result 
  196. of chance choices about things that are unreliable in the real world, such 
  197. as the power up state of unreset flip-flops. There is some more about this 
  198. in the example file TLIGHTS.LSM that should accompany this manual.
  199.  
  200.      The maximum size of the simulated circuit depends on the amount of 
  201. memory available to the program. A simulation of a circuit with 10000 2 
  202. input gates and 2500 named nodes which keeps track of the past 20 states 
  203. of each named signal occupies very roughly 300K. This is about the maximum 
  204. I would expect from a 512K ST with a few desk accessories. Machines with 
  205. more memory may simulate larger circuits, or keep track of more past 
  206. states etc.
  207.  
  208.      When Lsim has constructed the data base it uses the remaining memory 
  209. to store the past states of the circuit signals. Thus if your circuit is 
  210. nearly too big Lsim will only store a few past states of each signal. With 
  211. small circuits the buffer for storing past states is large, and may well 
  212. not be filled by even quite a long simulation.
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.      Section 3  The  Lsim  circuit  description  language
  223.  
  224.  
  225.  
  226.  
  227.      The Lsim language is best explained in a tutorial (waffle) fashion. 
  228. To make circuit diagrams drawn with ASCII character graphics clearer I 
  229. will adhere to the convention that a circuit's inputs are on its left, and 
  230. its output on its right.
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.      3.1  Circuit description statements
  238.  
  239.  
  240.      Consider first a very simple circuit consisting of a single 2 input 
  241. and gate. This circuit has 2 inputs which I will call A and B. Represented 
  242. as a circuit diagram it would look something like this:-
  243.  
  244.                               ________
  245.                        A -----|      |
  246.                               | and  |-----
  247.                        B -----|______|
  248.  
  249. Given that the symbol for AND in the Lsim language is just a dot (.) you 
  250. will not be surprised to learn that this circuit is represented by:-
  251.  
  252.                               A.B
  253.  
  254.      Suppose now that we wish to take the output of our AND gate and OR it 
  255. with a third input called C, as in the following circuit diagram:-
  256.  
  257.                       ________
  258.                A -----|      |
  259.                       | and  |______
  260.                B -----|______|     |
  261.                                    |     ________
  262.                                    |_____|      |
  263.                                          |  or  |-----
  264.                C ------------------------|______|
  265.  
  266. Again given that the symbol for OR in the Lsim language is a plus (+) you 
  267. will not be surprised to learn that this circuit is represented by:-
  268.  
  269.                               A.B+C
  270.  
  271.      This all seems very natural. We are used to the idea of AND having a 
  272. higher priority than OR in boolean expressions (just as multiplication has 
  273. a higher priority than addition in arithmetic expressions). Lsim 
  274. interprets boolean expressions according to the normal priorities so there 
  275. is no danger of thinking that:-
  276.  
  277.                               A.B+C
  278.  
  279. represents:-
  280.                                          ________
  281.                A ------------------------|      |
  282.                                    ______| and  |-----
  283.                                    |     |______|
  284.                       ________     |
  285.                B -----|      |     |
  286.                       |  or  |_____|
  287.                C -----|______|
  288.  
  289.  
  290. To represent this circuit (with the OR coming before the AND) we must use 
  291. brackets:-
  292.  
  293.                               A.(B+C)
  294.  
  295. Again the use of the brackets to force the OR to be done first follows 
  296. quite naturally from the way we are used to writing boolean expressions.
  297.  
  298.      It would however be a mistake to assume that the Lsim language 
  299. behaves just like boolean algebra, or indeed just like Palasm or Abel 
  300. equations. There is a subtle but extremely important difference connected 
  301. to the use of the equals (=) symbol. So far I've avoided mentioning this 
  302. difference by not mentioning what happens to the output from the example 
  303. circuits I've been discussing. But the time has come to grab the bull by 
  304. the tail and look the facts in the face.
  305.  
  306.      In designing the Lsim language my number 1 priority was to provide an 
  307. accurate representation of digital electronics, in order to ensure the 
  308. integrity of the simulation. THE LSIM LANGUAGE IS BEST THOUGHT OF AS A 
  309. CONDENSED AND VERY SYMBOLIC CIRCUIT DIAGRAM, which is what it really is. 
  310. The similarity to boolean algebra makes this form of circuit diagram easy 
  311. to read but can be misleading, as you will see with the equals sign.
  312.  
  313.      Consider a circuit consisting of two 2 input AND gates. Call the 
  314. inputs of the 1st gate A & B and the inputs of the 2nd gate C & D. Connect 
  315. the outputs of the AND gates together (with a piece of wire). The circuit 
  316. diagram for this is:-
  317.  
  318.                                ________
  319.                         A -----|      |
  320.                                | and  |______
  321.                         B -----|______|     |
  322.                                             |
  323.                                ________     |-----
  324.                         C -----|      |     |
  325.                                | and  |_____|
  326.                         D -----|______|
  327.  
  328.      I know that as it stands this circuit is useless, but it is never the 
  329. less possible to build such a circuit. Since you can build it and draw its 
  330. circuit diagram, you can represent it in the Lsim language. Like this:-
  331.  
  332.                               A.B=C.D
  333.  
  334.      This introduces the symbol for connection with a piece of wire: the 
  335. equals sign (=). Of course there is no boolean expression corresponding to 
  336. this circuit, and it can't be described in either Palasm or Abel. Since 
  337. the equals symbol means connect the two sides together with wire the it 
  338. can occur more than once in an expression. For example this circuit:-
  339.  
  340.                                ________
  341.                         A -----|      |
  342.                                | and  |______
  343.                         B -----|______|     |
  344.                                             |
  345.                                ________     |-----
  346.                         C -----|      |     |
  347.                                | and  |_____|
  348.                         D -----|______|     |
  349.                                             |
  350.                                ________     |
  351.                         E -----|      |     |
  352.                                | and  |_____|
  353.                         F -----|______|
  354.  
  355. is represented by:-
  356.  
  357.                               A.B=C.D=E.F
  358.  
  359.      The equals (=) symbol has a priority just like the AND (.) and OR (+) 
  360. symbols you've already met. In fact it has the lowest priority of all. To 
  361. represent a circuit like this:-
  362.  
  363.                            ________
  364.          A ----------------|      |          ________
  365.                       _____| and  |----------|      |
  366.          B -----|     |    |______|     _____| and  |-----
  367.                 |_____|                 |    |______|
  368.                 |                       |
  369.          C -----|                       |
  370.                                         |
  371.          D -----------------------------|
  372.  
  373. requires brackets, like this:-
  374.  
  375.                               A.(B=C).D
  376.  
  377. The unbracketed expression:-
  378.  
  379.                               A.B=C.D
  380.  
  381. in which the ANDs take priority over the equals is of course the 1st 
  382. circuit I showed you that used the equals symbol:-
  383.  
  384.                                ________
  385.                         A -----|      |
  386.                                | and  |______
  387.                         B -----|______|     |
  388.                                             |
  389.                                ________     |-----
  390.                         C -----|      |     |
  391.                                | and  |_____|
  392.                         D -----|______|
  393.  
  394.      Shorting together the outputs of and gates is fairly useless, but 
  395. shorting together the outputs of tristate buffers (such as the ubiquitous 
  396. 74LS244) is common and useful. Usually control logic ensures that only 1 
  397. tristate buffer on any given line is enabled at any given moment. In 7400 
  398. style chips (like the '244) the output enable is generally active low, but 
  399. in popular PALs such as the 16L8 it is active high. For the Lsim language 
  400. I chose to copy the PALs and provide as a basic element a tristate buffer 
  401. with an active high enable.
  402.  
  403.      Consider a circuit with 2 inputs. An input called A which is passed 
  404. to a tristate buffer controlled by the other input, called B. When B is 
  405. high the tristate buffer is enabled and the output of the circuit is A. 
  406. When B is low the tristate buffer is disabled (set to the 'off' state) and 
  407. the output of the circuit is a high impedance. Represented as a circuit 
  408. diagram it would look something like this:-
  409.  
  410.                                   ________
  411.                                   |      |
  412.                            A -----| tri  |-----
  413.                                   |______|
  414.                                       |OE
  415.                                       |
  416.                            B ---------|
  417.  
  418. which is represented in the Lsim language by:-
  419.  
  420.                               B?A
  421.  
  422.      The output enable (?) has the second lowest priority, the only thing 
  423. with a lower priority is the equals (=). For example the Lsim expression:-
  424.  
  425.                               B+C?A
  426.  
  427. represents:-
  428.  
  429.                                        ________
  430.                                        |      |
  431.                   A -------------------| tri  |-----
  432.                                        |______|
  433.                                            |OE
  434.                          ________          |
  435.                   B -----|      |          |
  436.                          |  or  |__________|
  437.                   C -----|______|
  438.  
  439. while in order to represent:-
  440.  
  441.                                             ________
  442.                   B ------------------------|      |
  443.                                       ______|  or  |-----
  444.                          ________     |     |______|
  445.                          |      |     |
  446.                   A -----| tri  |_____|
  447.                          |______|
  448.                              |OE
  449.                              |
  450.                   C ---------|
  451.  
  452. we must use brackets, like this:-
  453.  
  454.                               B+(C?A)
  455.  
  456.      There are 2 more gates that Lsim models directly: the NOT gate; and 
  457. the XOR gate. These behave exactly as you would expect having read thus 
  458. far.
  459.  
  460.      A circuit consisting of an XOR gate with 2 inputs A and B:-
  461.  
  462.                               ________
  463.                        A -----|      |
  464.                               | xor  |-----
  465.                        B -----|______|
  466.  
  467. is represented in the Lsim language by:-
  468.  
  469.                               A$B
  470.  
  471. The priority of the XOR ($) is the same as that of the OR (+). Although 
  472. Jerry Pournelle says you can never have too many examples I will spare you 
  473. (and me) the tedium of examples concerning the priority of the XOR ($).
  474.  
  475.      A circuit consisting of a NOT gate with 1 input A:-
  476.  
  477.                               ________
  478.                               |      |
  479.                        A -----| not  |-----
  480.                               |______|
  481.  
  482. is represented in the Lsim language by:-
  483.  
  484.                               /A
  485.  
  486. NOT (/) has the highest priority of all. Thus to represent the NAND gate:-
  487.  
  488.                               ________
  489.                        A -----|      |
  490.                               | nand |-----
  491.                        B -----|______|
  492.  
  493. we must use brackets, like this:-
  494.  
  495.                               /(A.B)
  496.  
  497. while the unbracketed expression:-
  498.  
  499.                               /A.B
  500.  
  501. represents:-
  502.  
  503.                       ________
  504.                       |      |
  505.                A -----| not  |______
  506.                       |______|     |
  507.                                    |     ________
  508.                                    |_____|      |
  509.                                          | and  |-----
  510.                B ------------------------|______|
  511.  
  512. of course.
  513.  
  514.      Users of Palasm be warned: it is possible for a single equation to be 
  515. syntactically valid in both Palasm and Lsim, but to mean different things 
  516. in each language. The following Palasm equation describes an output cell 
  517. of a 16L8 used as a nor gate:-
  518.  
  519.      /A = B + C
  520.  
  521.      This Palasm circuit looks like this:-
  522.  
  523.                               ________
  524.                        B -----|      |
  525.                               | nor  |----- A
  526.                        C -----|______|
  527.  
  528.  
  529.      While in Lsim the same statement describes a circuit made by 
  530. connecting the output of a not gate to the output of an or gate, like 
  531. this:-
  532.                                ________
  533.                                |      |
  534.                         A -----| not  |______
  535.                                |______|     |
  536.                                             |
  537.                                ________     |-----
  538.                         B -----|      |     |
  539.                                |  or  |_____|
  540.                         C -----|______|
  541.  
  542.  
  543.  
  544.  
  545.      I have now introduced all the 'operators' in the Lsim language. Note 
  546. that there is nothing corresponding to an 'assignment' operator, the 
  547. equals symbol being used to indicate connection with a piece of wire - a 
  548. quite different concept.
  549.  
  550.      In a real circuit as well as being connected to the outputs from 
  551. other gates, inputs may be connected to the positive supply or to ground. 
  552. The Lsim language uses the symbols 0 and 1 for ground (logic low), and the 
  553. positive supply (logic high) respectively. Thus, for example. the use of a 
  554. spare XOR gate as an inverter (of the signal A) would be written:-
  555.  
  556.                                    1$A
  557.  
  558. representing:-
  559.                               ________
  560.                        A -----|      |
  561.                               | xor  |-----
  562.          Positive supply -----|______|
  563.  
  564.  
  565.      The reader will have noticed a certain ambiguity in the Lsim language 
  566. so far described, for example consider the Lsim fragment:-
  567.  
  568.                                   A?B?C
  569.  
  570. Does this represent:-
  571.  
  572.                          ________           ________
  573.                          |      |           |      |
  574.                   C -----| tri  |-----------| tri  |-----
  575.                          |______|           |______|
  576.                              |OE                |OE
  577.                              |                  |
  578.                   B ---------|                  |
  579.                                                 |
  580.                                                 |
  581.                   A ----------------------------|
  582.  
  583. Or does it represent:-
  584.                                        ________
  585.                                        |      |
  586.                   C -------------------| tri  |-----
  587.                                        |______|
  588.                                            |OE
  589.                          ________          |
  590.                          |      |          |
  591.                   B -----| tri  |__________|
  592.                          |______|
  593.                              |OE
  594.                              |
  595.                   A ---------|
  596.  
  597.  
  598.      We can make the original fragment unambiguous with brackets: thus 
  599. A?(B?C) unambiguously represents the 1st circuit, and (A?B)?C the 2nd 
  600. circuit.
  601.  
  602.      In situations like A?B?C where priorities and brackets don't fully 
  603. define a circuit Lsim always takes the operators '=', '?' and '/' strictly 
  604. in right to left order. The other operators: '.', '+', and '$' are taken 
  605. strictly in left to right order. Thus A?B?C represents the same as A?(B?C) 
  606. and not (A?B)?C. But A$B+C represents the same as (A$B)+C and not A$(B+C).
  607.  
  608.  
  609.  
  610.      There is a multiplexing technique that uses tristate buffers. Because 
  611. it inserts only 1 gate delay in the signal path this technique is very 
  612. popular when more than 2 signals need to be multiplexed onto a single line 
  613. very rapidly. It is used, for example, in the Acorn BBC micro to multiplex 
  614. the memory addresses between the 6502 CPU, the 6845 CRTC and the SA5050 
  615. teletext chip. I will give it as an example because it uses both the = and 
  616. the ?, the 2 elements of the Lsim language different from Palasm and Abel 
  617. (and boolean algebra).
  618.  
  619.      Suppose we have 3 signals: S0, S1, and S2 that we wish to multiplex 
  620. onto a single line Y under the control of 3 control signals: C0, C1, and 
  621. C2. When control input C0 is high signal S0 is multiplexed onto Y. C1 and 
  622. C2 behave similarly. Of course the control logic generating C0-C2 must 
  623. ensure that only 1 control line is high at a time. A circuit for this 
  624. multiplexer is:-
  625.  
  626.                            ________
  627.                            |      |
  628.           S0 --------------| tri  |--------------|
  629.                            |______|              |
  630.                                |OE               |
  631.                                |                 |---------- Y
  632.           C0 ------------------|                 |
  633.                                                  |
  634.                            ________              |
  635.                            |      |              |
  636.           S1 --------------| tri  |--------------|
  637.                            |______|              |
  638.                                |OE               |
  639.                                |                 |
  640.           C1 ------------------|                 |
  641.                                                  |
  642.                            ________              |
  643.                            |      |              |
  644.           S2 --------------| tri  |--------------|
  645.                            |______|
  646.                                |OE
  647.                                |
  648.           C2 ------------------|
  649.  
  650.      As is, I hope, clear by now this would have the following representa-
  651. tion in the Lsim language:-
  652.  
  653.                            Y=C0?S0=C1?S1=C2?S2
  654.  
  655. The Y= bit may look like the start of an assignment, but all it really 
  656. means is connection with a piece of wire to point Y in the circuit.
  657.  
  658.      Suppose that the inverse of Y was also of interest, a signal I'll 
  659. call Y_ (the underscore is legal in Lsim names). The circuit to generate Y 
  660. and Y_ might be written:-
  661.  
  662.                         /(Y=C0?S0=C1?S1=C2?S2)=Y_
  663.  
  664. It might also be written (introducing the semicolon):-
  665.  
  666.                            Y_=/Y;
  667.                            Y=C0?S0=C1?S1=C2?S2;
  668.  
  669. or indeed:-
  670.  
  671.                            Y=C0?S0=C1?S1=C2?S2;
  672.                            Y_=/Y;
  673.  
  674.      The semicolon does just what you'd expect: it separates the circuit 
  675. description into convenient chunks called circuit description statements. 
  676. Every statement in the Lsim language must end in a semicolon.
  677.  
  678.      Remember that these statements are really a form of circuit diagram. 
  679. Changing the order of the circuit description statements in an Lsim input 
  680. file makes no difference to its meaning, just as changing the order of the 
  681. sheets in a circuit diagram spread over several sheets makes no difference 
  682. to its meaning.
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.      3.2  Declaration Statements
  690.  
  691.  
  692.      There is only 1 other kind of statement in the Lsim language: the 
  693. declaration statement. Each named point or signal in a circuit (such as 
  694. C0, C1, C2, S0, S1, S2, Y, and Y_ in the above example) must be declared 
  695. before it can be used in a circuit description statement.
  696.  
  697.      A declaration statement must start with an exclamation mark (!). This 
  698. is followed by a list of signal names to be declared. The names in the 
  699. list are separated with commas, and terminated with a semicolon. Only the 
  700. first 12 characters of a signal name are significant. Adding the 
  701. appropriate declaration to the multiplexer example gives:-
  702.  
  703.                      ! C0,C1,C2,S0,S1,S2,Y,Y_;
  704.  
  705.                      Y_=/Y;
  706.                      Y=C0?S0=C1?S1=C2?S2;
  707.  
  708.      These 3 lines are now a complete Lsim input file for simulating the 
  709. multiplexer. There is more that could be added to this input file, but 
  710. these 3 lines are a minimum that will work.
  711.  
  712.      There is a little more declaration syntax to be described. Each 
  713. signal name in a declaration list may be optionally followed by either 
  714. '=0', or '=1'.
  715.  
  716.      There is something (explained later) called the user gate associated 
  717. with each named signal. This may be initialised at the start of the 
  718. simulation to either tristate, or logic high or logic low. Signal names 
  719. appearing on their own in a declaration statement (like C0 etc. above) 
  720. have their user gates initialised to tristate. Signals followed by =0 have 
  721. their user gates initialised to logic low, while signals followed by =1 
  722. have their user gates initialised to logic high. Sensible initial settings 
  723. for the multiplexer example might be:-
  724.  
  725.                   ! C0=1,C1=0,C2=0,S0=0,S1=0,S2=0,Y,Y_;
  726.  
  727.                   Y_=/Y;
  728.                   Y=C0?S0=C1?S1=C2?S2;
  729.  
  730.      As is explained later this will cause the simulation to start with S0 
  731. selected and all data inputs low.
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.      3.3  Character set and comments
  739.  
  740.  
  741.      All text appearing enclosed in curly brackets { } is a comment, and 
  742. is ignored by Lsim. Comments do nest - so it is possible to comment out 
  743. commented parts of the input file {and to make comment nesting errors}. A 
  744. comment can appear literally anywhere - including the middle of a signal 
  745. name.
  746.  
  747.      No special character is required to mark the end of an Lsim input 
  748. file, the occurrence of end of file is taken as an end mark.
  749.  
  750.      An Lsim input file can contain any character, however only the 
  751. printable characters in the range 21 hex "!" to 7E hex "~" inclusive are 
  752. significant, all other characters are ignored. Note that as well as 
  753. carriage return, newline, tab, etc. space is also ignored.
  754.  
  755.      Like comments, ignored characters can appear anywhere - it is even 
  756. possible to have spaces and carriage returns etc. in the middle of a 
  757. signal name. I'm not sure that this was such a good idea, even if it is 
  758. the same as Algol 68 and I'm not even sure of that. It does however mean 
  759. that the Lsim language is fairly free format. The multiplexer example 
  760. might be laid out like this:-
  761.  
  762.  
  763.         {----     Multiplexer example from Lsim tutorial     ----}
  764.  
  765.  
  766.         ! C0 = 1, C1 = 0, C2 = 0, S0 = 0, S1 = 0, S2 = 0, Y, Y_ ;
  767.  
  768.  
  769.         Y_ = /Y ;
  770.  
  771.         Y  = C0 ? S0
  772.            = C1 ? S1
  773.            = C2 ? S2 ;
  774.  
  775.  
  776. as in the file MPLEX.LSM that should accompany this document.
  777.  
  778.      Apart from the following special characters:-
  779.  
  780.                           ! /.+$?= () ;, {} 0 1
  781.  
  782. any non-ignored character can be used in a signal name. The special 
  783. characters 0 and 1 may also appear in a signal name provided it isn't a 
  784. single character name. Thus 'DataBusBit0' is a legal name, as is '10More', 
  785. but not '1' on its own.
  786.  
  787.      As an aside let me recommend to the reader the convention of using a 
  788. trailing underscore to indicate an "active low" signal. I have found this 
  789. most useful, especially as both Palasm and Abel accept the underscore in a 
  790. pin name.
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.      Section 4  The  nature  of  the  interactive  simulation
  801.  
  802.  
  803.  
  804.      4.1  Input
  805.  
  806.  
  807.      The time has come to explain the previously mentioned user gate. Most 
  808. digital electronic systems have input signals, and output signals. Many 
  809. have signals (such as data buses) which are both.
  810.  
  811.      During a simulation the user must be able to set the values at the 
  812. inputs to the system being simulated. Lsim lets the user set one of three 
  813. values at each input: logic high, logic low and tristate. It is as though 
  814. each input is connected to the output of a tristate buffer under the 
  815. user's control. I have called this tristate buffer the user gate.
  816.  
  817.      In Lsim every named signal is treated as an input, and has a user 
  818. gate connected to it. During a simulation if the named signal is set to 
  819. logic high, and the user gate connected to it is set to logic low the 
  820. simulation will show contention. Just as it does when high and low outputs 
  821. of "ordinary" gates are connected together. Apart from being under the 
  822. user's control the user gate behaves just like any other tristate buffer 
  823. in the simulation.
  824.  
  825.      Probably most of the named signals were not intended to be inputs, 
  826. some may even be meant to be non-tristate outputs. Because Lsim simulates 
  827. tristate this is not a problem. The user gates connected to these signals 
  828. are simply left set to tristate throughout the simulation, in which case 
  829. it is as though they wern't there.
  830.  
  831.      The simulation of a bi-directional input, such as a line of a data 
  832. bus, is also easy. When the line is to be used as an output the user 
  833. tristates its user gate, when it is used as an input the user gate is set 
  834. high or low as appropriate. It is not difficult for the user to mimic the 
  835. bus cycles of CPUs like this, allowing the random "glue" logic of a 
  836. computer system, or the interface logic of a bus card to be easily 
  837. simulated.
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.      4.2  Progress through time
  845.  
  846.  
  847.      Simulation proceeds as a series of discreet steps from one logical 
  848. state to the next. The user tells Lsim when to step on to the next state.
  849. Inbetween steps the user can change the states of the user gates.
  850.  
  851.      Lsim calculates the next state iteratively. A step of the iteration 
  852. consists of going through all the gates in the system, and setting their 
  853. outputs appropriately to their inputs. This process is repeated until none 
  854. of the outputs change state.
  855.  
  856.      In this way Lsim imitates a system in which all the gates have 
  857. infinitesimal propagation delay. Obviously it is possible to have infinite 
  858. loops, such as:-
  859.  
  860.                                A = /A
  861.  
  862.      There is no way for Lsim to detect the presence of an infinite loop, 
  863. which can be a good deal more subtle than the above example. In order to 
  864. prevent the program hanging in an infinite loop it pauses on every 23rd 
  865. iteration of the settling loop and prompts. The user may either continue 
  866. for another 23 cycles, or abort the attempt to calculate the next state. 
  867. In case the cause of the infinite loop isn't clear, it is possible to 
  868. single step the simulation one iteration of the settling loop at a time.
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.      4.3  Cheating
  876.  
  877.  
  878.      The user gates are the main method of interaction with the circuit 
  879. being simulated. However this interaction is, so to speak, once removed 
  880. from the circuit itself.
  881.  
  882.      With the user gate it is not possible to directly alter the state of 
  883. a named signal, only to change the state of the output of a gate connected 
  884. to the named signal. The named signal may have other outputs connected to 
  885. it as well. If one of the other outputs is set to logic high it is 
  886. impossible to force the signal to logic low with the user gate. Setting 
  887. the output of the user gate to logic low will simply cause the signal to 
  888. go contended.
  889.  
  890.      Logic designed using a finite state machine metaphor may have 
  891. unreachable states. Sometimes, for test purposes, it is interesting to 
  892. know what the logic does if it gets into an unreachable state. There can 
  893. be lots of reasons for wanting to directly set the state of a given signal 
  894. in the circuit being simulated.
  895.  
  896.      Lsim keeps a record of the current state of each named signal in 
  897. memory. It is possible to directly edit this record, and so set any named 
  898. signal to logic high, logic low or tristate. Of course doing this breaks 
  899. the logical integrity of the simulation - in the sense that it can do 
  900. things real logic wouldn't do. For example the output of an AND gate with 
  901. low inputs can be forced high.
  902.  
  903.      I have found this "cheat" feature useful to get sequential logic out 
  904. of stuck states, particularly ones where lots of signals are undetermined. 
  905. However normally I always use the user gate route for interaction, as it 
  906. preserves the logical integrity of the simulation.
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.      Section 5                Running  Lsim
  917.  
  918.  
  919.  
  920.      Lsim's opening screen is very simple. It just prompts you for the 
  921. name of the input file and the name of the output file. If you don't want 
  922. an output file simply type a carriage return at the output file prompt. 
  923. The output file is a copy of the input file with the error messages added 
  924. to it. Lsim also looks for the input and output file names in the command 
  925. line image TOS passes it.
  926.  
  927.      Assuming that your input file had no syntax errors you get to the 
  928. simulation. This draws the timing diagram on the screen. No past states of 
  929. signals are shown at first. Pressing return will step the simulation, and 
  930. generate the first state.
  931.  
  932.      The timing diagram is how Lsim presents its output to the user. Each 
  933. named signal has a line to itself in the timing diagram. The line starts 
  934. with the name of the signal. Then it shows the past states of the signal 
  935. (most recent state rightmost) using the following symbols:- 
  936.  
  937.  
  938.      xxx  Undetermined (e.g the output of a gate with tristated inputs)
  939.  
  940.      !!!  Contended    (e.g. a logic high connected to a logic low)
  941.  
  942.      ...  Tristate     (high impedance)
  943.  
  944.      ¯¯¯  Logic High   (the same as 1) { weirdy Atari char - unprintable }
  945.  
  946.      ___  Logic Low    (the same as 0)
  947.  
  948.  
  949.      At the right hand end of the line the state of the output of the user 
  950. gate connected to the signal is shown using the following symbols:-
  951.  
  952.  
  953.      .    Tristate     (high impedance)
  954.  
  955.      1    Logic High   (the same as ¯¯¯)
  956.  
  957.      0    Logic Low    (the same as ___)
  958.  
  959.  
  960.      The signals appear in the timing diagram in the order in which they 
  961. are declared in the input file. This fact (at last) completes the 
  962. semantics of the Lsim language.
  963.  
  964.      If the simulation has been stepped more times than will fit across 
  965. the screen, the right and left arrow keys can be used to scroll the 
  966. display forwards and backwards in time.
  967.  
  968.      When the display is scrolled backwards in time the rightmost signal 
  969. states on the screen are no longer the current states. Lsim indicates this 
  970. by removing the states of the user gates from the display. The simulation 
  971. may only be stepped when the display is scrolled as far forwards in time 
  972. as possible and the user gate information is shown.
  973.  
  974.      A line cursor (moved by the up and down arrow keys) is provided to 
  975. indicate which signal is to have its user gate set. The Insert, and 
  976. clr/home keys turn this cursor on and off. Full stop, Number 0, and Number 
  977. 1 keys set the value of the line cursor signal's user gate. It is only 
  978. possible to set a user gates value when the user gate information is shown 
  979. and the line cursor is on.
  980.  
  981.      Escape lets you out.
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.      Appendix 1  Quick key guide
  992.  
  993.  
  994.  
  995.                 Key    Action
  996.                 ===    ======
  997.  
  998.              Insert    show line cursor
  999.            Clr/Home    hide line cursor
  1000.  
  1001.            up arrow    move line cursor up (scroll if at top)
  1002.          down arrow    move line cursor down (scroll if at bottom)
  1003.      Shift up arrow    scroll display up
  1004.    Shift down arrow    scroll display down
  1005.  
  1006.          left arrow    scroll display backwards in time 1 state
  1007.         right arrow    scroll display forwards in time 1 state
  1008.    Shift left arrow    scroll display backwards in time 5 states
  1009.   Shift right arrow    scroll display forwards in time 5 states
  1010.  Control left arrow    scroll display backwards in time all the way
  1011. Control right arrow    scroll display forwards in time all the way
  1012.  
  1013.                   0    set the line cursor user gate to logic low
  1014.                   1    set the line cursor user gate to logic high
  1015.                   .    set the line cursor user gate to tristate
  1016.  
  1017.           Control 0    force the line cursor signal to logic low (cheat)
  1018.           Control 1    force the line cursor signal to logic high (cheat)
  1019.           Control .    force the line cursor signal to tristate (cheat)
  1020.  
  1021.        Return/Enter    calculate the next state of the simulation
  1022.                   S    single step the settling loop
  1023.                   P    redraw the screen
  1024.  
  1025.                 Esc    terminate the program
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.      Appendix 2  A summary of the Lsim language
  1036.  
  1037.  
  1038.  
  1039.      A2.1 Operators
  1040.  
  1041.      The operators in order of priority (highest first) are:-
  1042.  
  1043.      Symbol    Operator                   Direction of elaboration
  1044.      ======    ========                   ========= == ===========
  1045.  
  1046.       /        Not                        Right to left
  1047.  
  1048.       .        And                        Left to right
  1049.      + $       Or Xor (equal priority)    Left to right
  1050.       ?        Output enable              Right to left
  1051.       =        Connection (with wire)     Right to left
  1052.  
  1053.  
  1054.  
  1055.      A2.2 Comments
  1056.  
  1057.      Anything enclosed in curly brackets { } is comment. Comments nest.
  1058.  
  1059.  
  1060.  
  1061.      A2.3 Character set
  1062.  
  1063.      Space is not a significant character. Only the following are:-
  1064.  
  1065.            !"#$%&'()*+,-./0123456789:;<=>?
  1066.           @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
  1067.           `abcdefghijklmnopqrstuvwxyz{|}~
  1068.  
  1069.  
  1070.      Any non-significant characters in the input file are ignored.
  1071.  
  1072.  
  1073.  
  1074.      A2.4 Signal names
  1075.  
  1076.      Signal names may contain only the following characters:-
  1077.  
  1078.             "# %&'  *  -  0123456789: < >
  1079.           @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
  1080.           `abcdefghijklmnopqrstuvwxyz | ~
  1081.  
  1082.      of which only the first 12 are significant.
  1083.      The single character names 0 and 1 are used as the logical constants.
  1084.  
  1085.  
  1086.  
  1087.      A2.5 Grammar
  1088.  
  1089.      The grammar of the Lsim language input file is:-
  1090.  
  1091.  
  1092.           <input file>
  1093.                <statement> <input file>
  1094.                <statement>
  1095.  
  1096.           <statement>
  1097.                <declaration statement>
  1098.                <circuit description statement>
  1099.  
  1100.  
  1101.  
  1102.           <declaration statement>
  1103.                ! <declaration list> ;
  1104.  
  1105.           <declaration list>
  1106.                <declaretor> , <declaration list>
  1107.                <declaretor>
  1108.  
  1109.           <declaretor>
  1110.                <signal name>
  1111.                <signal name> = 0
  1112.                <signal name> = 1
  1113.  
  1114.  
  1115.  
  1116.           <circuit description statement>
  1117.                <wire term> ;
  1118.  
  1119.           <wire term>
  1120.                <gate term> = <wire term>
  1121.                <gate term>
  1122.  
  1123.           <gate term>
  1124.                <sum term> ? <gate term>
  1125.                <sum term>
  1126.  
  1127.           <sum term>
  1128.                <sum term> + <product term>
  1129.                <sum term> $ <product term>
  1130.                <product term>
  1131.  
  1132.           <product term>
  1133.                <product term> . <unary>
  1134.                <unary>
  1135.  
  1136.           <unary>
  1137.                / <unary>
  1138.                ( <wire term> )
  1139.                <primitive>
  1140.  
  1141.           <primitive>
  1142.                <signal name>
  1143.                0
  1144.                1
  1145.  
  1146.  
  1147.      The terminal symbols of this grammar are:-
  1148.  
  1149.           <signal name>
  1150.  
  1151.      and the literal characters
  1152.  
  1153.           ! /.+$?= () ;, 0 1
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.      Appendix 3  Operator truth tables
  1164.  
  1165.  
  1166.  
  1167.      The truth tables use these abrieviations:-
  1168.  
  1169.      tri  - Tristated (high impedance)
  1170.      lo   - Logic Low
  1171.      hi   - Logic High
  1172.      cont - Contended
  1173.      udet - Undetermined
  1174.  
  1175.      In the case of a binary operator the right operand is shown along the 
  1176. top of the table, and the left operand down the left hand side of the 
  1177. table.
  1178.  
  1179.  
  1180.  
  1181.                 NOT  / |   tri    lo     hi     cont   udet
  1182.                 -------+-----------------------------------
  1183.                        |   udet   hi     lo     udet   udet
  1184.  
  1185.  
  1186.  
  1187.                 AND  . |   tri    lo     hi     cont   udet
  1188.                 -------+-----------------------------------   
  1189.                 tri    |   udet   lo     udet   udet   udet
  1190.                 lo     |   lo     lo     lo     lo     lo
  1191.                 hi     |   udet   lo     hi     udet   udet
  1192.                 cont   |   udet   lo     udet   udet   udet
  1193.                 udet   |   udet   lo     udet   udet   udet
  1194.  
  1195.  
  1196.  
  1197.                 OR   + |   tri    lo     hi     cont   udet
  1198.                 -------+-----------------------------------
  1199.                 tri    |   udet   udet   hi     udet   udet
  1200.                 lo     |   udet   lo     hi     udet   udet
  1201.                 hi     |   hi     hi     hi     hi     hi
  1202.                 cont   |   udet   udet   hi     udet   udet
  1203.                 udet   |   udet   udet   hi     udet   udet
  1204.  
  1205.  
  1206.  
  1207.                 XOR  $ |   tri    lo     hi     cont   udet
  1208.                 -------+-----------------------------------
  1209.                 tri    |   udet   udet   udet   udet   udet
  1210.                 lo     |   udet   lo     hi     udet   udet
  1211.                 hi     |   udet   hi     lo     udet   udet
  1212.                 cont   |   udet   udet   udet   udet   udet
  1213.                 udet   |   udet   udet   udet   udet   udet
  1214.  
  1215.  
  1216.  
  1217.                 OE   ? |   tri    lo     hi     cont   udet
  1218.                 -------+-----------------------------------
  1219.                 tri    |   udet   udet   udet   udet   udet
  1220.                 lo     |   tri    tri    tri    tri    tri
  1221.                 hi     |   udet   lo     hi     udet   udet
  1222.                 cont   |   udet   udet   udet   udet   udet
  1223.                 udet   |   udet   udet   udet   udet   udet
  1224.  
  1225.  
  1226.  
  1227.                 WIRE = |   tri    lo     hi     cont   udet
  1228.                 -------+-----------------------------------
  1229.                 tri    |   tri    lo     hi     cont   udet
  1230.                 lo     |   lo     lo     cont   cont   cont
  1231.                 hi     |   hi     cont   hi     cont   cont
  1232.                 cont   |   cont   cont   cont   cont   cont
  1233.                 udet   |   udet   cont   cont   cont   udet
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.      Appendix 4  Flip-flops
  1244.  
  1245.  
  1246.  
  1247.      Unfortunately Lsim doesn't (yet) support the flip-flop as a basic 
  1248. operator. This means that flip-flops must be specified at the gate level.
  1249.  
  1250.      In this appendix I will provide tested Lsim implementations of some 
  1251. common flip-flop types. They may be regarded as "black boxes" - it is easy 
  1252. to verify that they perform as advertised by using the simulator. This 
  1253. saves you the trouble of figuring out your own flip-flops. A process that 
  1254. can be more difficult than it might seem due to the way the undetermined 
  1255. state propagates through a simulation.
  1256.  
  1257.      G. Spencer-Brown in "The Laws of Form" (chap. 11, pp. 58, Time) shows 
  1258. that the property of memory in a logical system built from gates follows 
  1259. from circular or re-entrant information paths. Whilst 1 circle is enough 
  1260. for a level triggered transparent or set-reset latch, I strongly suspect 
  1261. (but haven't yet mathematically proved) that at least 2 circles are 
  1262. required for an edge triggered device.
  1263.  
  1264.      At any rate I have been unable to devise any Lsim representations of 
  1265. edge triggered flip-flops without naming at least 1 other point in the 
  1266. circuit besides the inputs and the output.
  1267.  
  1268.      This means that the edge triggered designs have an extra signal name 
  1269. (q1) associated with them. The behaviour of this signal need not concern 
  1270. the user, it can be regarded as being inside the flip-flop's black box. It 
  1271. is a good idea to declare these extra signal names last so they appear at 
  1272. the bottom of the timing diagram, and don't clutter up the action.
  1273.  
  1274.      If anyone does figure out an Lsim representation of a single output 
  1275. edge triggered flip-flop without using an extra internal signal name I 
  1276. would be very interested in seeing it. I can be contacted on CIX as jason.
  1277.  
  1278.      Here are 5 common flip-flops. For an example of the use of the 3rd 
  1279. flip-flop circuit in this list see the accompanying Lsim input file 
  1280. TLIGHTS.LSM.
  1281.  
  1282.  
  1283.  
  1284. 1) Transparent (level triggered) latch.
  1285.  
  1286.      ! D, { = data input }
  1287.        Q, { = data output }
  1288.        G; { = latch enable input (high = transparent, low = latched) }
  1289.  
  1290.      Q = (/G + D).(G.D + Q);
  1291.  
  1292.  
  1293.  
  1294.      The remaining designs are all edge triggered. In all cases I have 
  1295. written the equations to latch on the rising clock edge, and to have 
  1296. active high asynchronous (jam) set and clear inputs. It is easy to invert 
  1297. the polarity of any input signal if you want a falling edge clocked 
  1298. device, or active low set and clear lines.
  1299.  
  1300.  
  1301.  
  1302. 2) D-Type flip-flop with set and clear.
  1303.  
  1304.      ! D,     { = data input }
  1305.        Q,     { = data output }
  1306.        Clk,   { = rising edge triggered clock input }
  1307.        Set,   { = active high asynchronous set input }
  1308.        Clear, { = active high asynchronous clear input }
  1309.        q1;    { = extra signal internal to flip-flop }
  1310.  
  1311.      Q  = /Clear.(D + /Clk + q1).(Set + Q + D.Clk./q1);
  1312.  
  1313.      q1 = Clk.(q1 + Set + Clear + /(Q $ D));
  1314.  
  1315.  
  1316.  
  1317. 3) D-Type flip-flop without set and clear.
  1318.  
  1319.      ! D,     { = data input }
  1320.        Q,     { = data output }
  1321.        Clk,   { = rising edge triggered clock input }
  1322.        q1;    { = extra signal internal to flip-flop }
  1323.  
  1324.      Q  = (/Clk + q1 + D).(Clk./q1.D + Q);
  1325.  
  1326.      q1 = Clk.(q1 + /(Q $ D));
  1327.  
  1328.  
  1329.  
  1330. 4) J-K flip-flop with set and clear.
  1331.  
  1332.      ! J,     { = J input }
  1333.        K,     { = K input }
  1334.        Q,     { = data output }
  1335.        Clk,   { = rising edge triggered clock input }
  1336.        Set,   { = active high asynchronous set input }
  1337.        Clear, { = active high asynchronous clear input }
  1338.        q1;    { = extra signal internal to flip-flop }
  1339.  
  1340.      Q  = /(Clear + Clk.q1 + /(Set + Q + Clk./q1));
  1341.  
  1342.      q1 = /Set.(Clk
  1343.         + /(J./(K.Q) + /K.Q)).(Clear + q1 + /Clk.(K./(J./Q) + /J./Q));
  1344.  
  1345.  
  1346.  
  1347. 5) J-K flip-flop without set and clear.
  1348.  
  1349.      ! J,     { = J input }
  1350.        K,     { = K input }
  1351.        Q,     { = data output }
  1352.        Clk,   { = rising edge triggered clock input }
  1353.        q1;    { = extra signal internal to flip-flop }
  1354.  
  1355.      Q  = /(Clk.q1).(Q + Clk./q1);
  1356.  
  1357.      q1 = (Clk + /(J./(K.Q) + /K.Q)).(q1 + /Clk.(K./(J./Q) + /J./Q));
  1358.  
  1359.